import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'

Vue.config.productionTip = false

Vue.use(Antd)

// 路由守护
router.beforeEach((to, from, next) => {
  let userId = localStorage.getItem('userId')
  if (to.path == '/login') {
    if (userId) {
      router.push({path: '/'})
    }
    console.log('qqqq')
    next()
  } else {
    // 1.无登录信息的跳转到登录页
    if (userId == null) {
      router.push({path: '/login'})
    } else {
      next()
    }
  }
})

new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
